{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "a57ee0be-06f9-4127-94b2-296e18000a0c",
   "metadata": {},
   "outputs": [],
   "source": [
    "import os"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "ecee1fa9-2628-42ee-be79-766355e2eb55",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "200\n"
     ]
    }
   ],
   "source": [
    "path = r\"C:\\Users\\29036\\Desktop\\Car\\masks\\val\"\n",
    "files = os.listdir(path)\n",
    "image_files = []\n",
    "for f in files:\n",
    "    if f.endswith(\".jpg\"):\n",
    "        image_files.append(f)\n",
    "print(len(image_files))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "d3e97e54-87ed-4520-b4f0-8323adbe827f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "img_0.jpg\n",
      "Renamed 4fc2470c0f7b_09.jpg to img_0.jpg\n",
      "img_1.jpg\n",
      "Renamed 4fc2470c0f7b_10.jpg to img_1.jpg\n",
      "img_2.jpg\n",
      "Renamed 4fc2470c0f7b_11.jpg to img_2.jpg\n",
      "img_3.jpg\n",
      "Renamed 4fc2470c0f7b_12.jpg to img_3.jpg\n",
      "img_4.jpg\n",
      "Renamed 4fc2470c0f7b_13.jpg to img_4.jpg\n",
      "img_5.jpg\n",
      "Renamed 4fc2470c0f7b_14.jpg to img_5.jpg\n",
      "img_6.jpg\n",
      "Renamed 4fc2470c0f7b_15.jpg to img_6.jpg\n",
      "img_7.jpg\n",
      "Renamed 4fc2470c0f7b_16.jpg to img_7.jpg\n",
      "img_8.jpg\n",
      "Renamed 51f1cdf5f539_01.jpg to img_8.jpg\n",
      "img_9.jpg\n",
      "Renamed 51f1cdf5f539_02.jpg to img_9.jpg\n",
      "img_10.jpg\n",
      "Renamed 51f1cdf5f539_03.jpg to img_10.jpg\n",
      "img_11.jpg\n",
      "Renamed 51f1cdf5f539_04.jpg to img_11.jpg\n",
      "img_12.jpg\n",
      "Renamed 51f1cdf5f539_05.jpg to img_12.jpg\n",
      "img_13.jpg\n",
      "Renamed 51f1cdf5f539_06.jpg to img_13.jpg\n",
      "img_14.jpg\n",
      "Renamed 51f1cdf5f539_07.jpg to img_14.jpg\n",
      "img_15.jpg\n",
      "Renamed 51f1cdf5f539_08.jpg to img_15.jpg\n",
      "img_16.jpg\n",
      "Renamed 51f1cdf5f539_09.jpg to img_16.jpg\n",
      "img_17.jpg\n",
      "Renamed 51f1cdf5f539_10.jpg to img_17.jpg\n",
      "img_18.jpg\n",
      "Renamed 51f1cdf5f539_11.jpg to img_18.jpg\n",
      "img_19.jpg\n",
      "Renamed 51f1cdf5f539_12.jpg to img_19.jpg\n",
      "img_20.jpg\n",
      "Renamed 51f1cdf5f539_13.jpg to img_20.jpg\n",
      "img_21.jpg\n",
      "Renamed 51f1cdf5f539_14.jpg to img_21.jpg\n",
      "img_22.jpg\n",
      "Renamed 51f1cdf5f539_15.jpg to img_22.jpg\n",
      "img_23.jpg\n",
      "Renamed 51f1cdf5f539_16.jpg to img_23.jpg\n",
      "img_24.jpg\n",
      "Renamed 528eb34a4c29_01.jpg to img_24.jpg\n",
      "img_25.jpg\n",
      "Renamed 528eb34a4c29_02.jpg to img_25.jpg\n",
      "img_26.jpg\n",
      "Renamed 528eb34a4c29_03.jpg to img_26.jpg\n",
      "img_27.jpg\n",
      "Renamed 528eb34a4c29_04.jpg to img_27.jpg\n",
      "img_28.jpg\n",
      "Renamed 528eb34a4c29_05.jpg to img_28.jpg\n",
      "img_29.jpg\n",
      "Renamed 528eb34a4c29_06.jpg to img_29.jpg\n",
      "img_30.jpg\n",
      "Renamed 528eb34a4c29_07.jpg to img_30.jpg\n",
      "img_31.jpg\n",
      "Renamed 528eb34a4c29_08.jpg to img_31.jpg\n",
      "img_32.jpg\n",
      "Renamed 528eb34a4c29_09.jpg to img_32.jpg\n",
      "img_33.jpg\n",
      "Renamed 528eb34a4c29_10.jpg to img_33.jpg\n",
      "img_34.jpg\n",
      "Renamed 528eb34a4c29_11.jpg to img_34.jpg\n",
      "img_35.jpg\n",
      "Renamed 528eb34a4c29_12.jpg to img_35.jpg\n",
      "img_36.jpg\n",
      "Renamed 528eb34a4c29_13.jpg to img_36.jpg\n",
      "img_37.jpg\n",
      "Renamed 528eb34a4c29_14.jpg to img_37.jpg\n",
      "img_38.jpg\n",
      "Renamed 528eb34a4c29_15.jpg to img_38.jpg\n",
      "img_39.jpg\n",
      "Renamed 528eb34a4c29_16.jpg to img_39.jpg\n",
      "img_40.jpg\n",
      "Renamed 54ee69d7d5e5_01.jpg to img_40.jpg\n",
      "img_41.jpg\n",
      "Renamed 54ee69d7d5e5_02.jpg to img_41.jpg\n",
      "img_42.jpg\n",
      "Renamed 54ee69d7d5e5_03.jpg to img_42.jpg\n",
      "img_43.jpg\n",
      "Renamed 54ee69d7d5e5_04.jpg to img_43.jpg\n",
      "img_44.jpg\n",
      "Renamed 54ee69d7d5e5_05.jpg to img_44.jpg\n",
      "img_45.jpg\n",
      "Renamed 54ee69d7d5e5_06.jpg to img_45.jpg\n",
      "img_46.jpg\n",
      "Renamed 54ee69d7d5e5_07.jpg to img_46.jpg\n",
      "img_47.jpg\n",
      "Renamed 54ee69d7d5e5_08.jpg to img_47.jpg\n",
      "img_48.jpg\n",
      "Renamed 54ee69d7d5e5_09.jpg to img_48.jpg\n",
      "img_49.jpg\n",
      "Renamed 54ee69d7d5e5_10.jpg to img_49.jpg\n",
      "img_50.jpg\n",
      "Renamed 54ee69d7d5e5_11.jpg to img_50.jpg\n",
      "img_51.jpg\n",
      "Renamed 54ee69d7d5e5_12.jpg to img_51.jpg\n",
      "img_52.jpg\n",
      "Renamed 54ee69d7d5e5_13.jpg to img_52.jpg\n",
      "img_53.jpg\n",
      "Renamed 54ee69d7d5e5_14.jpg to img_53.jpg\n",
      "img_54.jpg\n",
      "Renamed 54ee69d7d5e5_15.jpg to img_54.jpg\n",
      "img_55.jpg\n",
      "Renamed 54ee69d7d5e5_16.jpg to img_55.jpg\n",
      "img_56.jpg\n",
      "Renamed 553c658b9efa_01.jpg to img_56.jpg\n",
      "img_57.jpg\n",
      "Renamed 553c658b9efa_02.jpg to img_57.jpg\n",
      "img_58.jpg\n",
      "Renamed 553c658b9efa_03.jpg to img_58.jpg\n",
      "img_59.jpg\n",
      "Renamed 553c658b9efa_04.jpg to img_59.jpg\n",
      "img_60.jpg\n",
      "Renamed 553c658b9efa_05.jpg to img_60.jpg\n",
      "img_61.jpg\n",
      "Renamed 553c658b9efa_06.jpg to img_61.jpg\n",
      "img_62.jpg\n",
      "Renamed 553c658b9efa_07.jpg to img_62.jpg\n",
      "img_63.jpg\n",
      "Renamed 553c658b9efa_08.jpg to img_63.jpg\n",
      "img_64.jpg\n",
      "Renamed 553c658b9efa_09.jpg to img_64.jpg\n",
      "img_65.jpg\n",
      "Renamed 553c658b9efa_10.jpg to img_65.jpg\n",
      "img_66.jpg\n",
      "Renamed 553c658b9efa_11.jpg to img_66.jpg\n",
      "img_67.jpg\n",
      "Renamed 553c658b9efa_12.jpg to img_67.jpg\n",
      "img_68.jpg\n",
      "Renamed 553c658b9efa_13.jpg to img_68.jpg\n",
      "img_69.jpg\n",
      "Renamed 553c658b9efa_14.jpg to img_69.jpg\n",
      "img_70.jpg\n",
      "Renamed 553c658b9efa_15.jpg to img_70.jpg\n",
      "img_71.jpg\n",
      "Renamed 553c658b9efa_16.jpg to img_71.jpg\n",
      "img_72.jpg\n",
      "Renamed 5588758ee21c_01.jpg to img_72.jpg\n",
      "img_73.jpg\n",
      "Renamed 5588758ee21c_02.jpg to img_73.jpg\n",
      "img_74.jpg\n",
      "Renamed 5588758ee21c_03.jpg to img_74.jpg\n",
      "img_75.jpg\n",
      "Renamed 5588758ee21c_04.jpg to img_75.jpg\n",
      "img_76.jpg\n",
      "Renamed 5588758ee21c_05.jpg to img_76.jpg\n",
      "img_77.jpg\n",
      "Renamed 5588758ee21c_06.jpg to img_77.jpg\n",
      "img_78.jpg\n",
      "Renamed 5588758ee21c_07.jpg to img_78.jpg\n",
      "img_79.jpg\n",
      "Renamed 5588758ee21c_08.jpg to img_79.jpg\n",
      "img_80.jpg\n",
      "Renamed 5588758ee21c_09.jpg to img_80.jpg\n",
      "img_81.jpg\n",
      "Renamed 5588758ee21c_10.jpg to img_81.jpg\n",
      "img_82.jpg\n",
      "Renamed 5588758ee21c_11.jpg to img_82.jpg\n",
      "img_83.jpg\n",
      "Renamed 5588758ee21c_12.jpg to img_83.jpg\n",
      "img_84.jpg\n",
      "Renamed 5588758ee21c_13.jpg to img_84.jpg\n",
      "img_85.jpg\n",
      "Renamed 5588758ee21c_14.jpg to img_85.jpg\n",
      "img_86.jpg\n",
      "Renamed 5588758ee21c_15.jpg to img_86.jpg\n",
      "img_87.jpg\n",
      "Renamed 5588758ee21c_16.jpg to img_87.jpg\n",
      "img_88.jpg\n",
      "Renamed 56023a17481b_01.jpg to img_88.jpg\n",
      "img_89.jpg\n",
      "Renamed 56023a17481b_02.jpg to img_89.jpg\n",
      "img_90.jpg\n",
      "Renamed 56023a17481b_03.jpg to img_90.jpg\n",
      "img_91.jpg\n",
      "Renamed 56023a17481b_04.jpg to img_91.jpg\n",
      "img_92.jpg\n",
      "Renamed 56023a17481b_05.jpg to img_92.jpg\n",
      "img_93.jpg\n",
      "Renamed 56023a17481b_06.jpg to img_93.jpg\n",
      "img_94.jpg\n",
      "Renamed 56023a17481b_07.jpg to img_94.jpg\n",
      "img_95.jpg\n",
      "Renamed 56023a17481b_08.jpg to img_95.jpg\n",
      "img_96.jpg\n",
      "Renamed 56023a17481b_09.jpg to img_96.jpg\n",
      "img_97.jpg\n",
      "Renamed 56023a17481b_10.jpg to img_97.jpg\n",
      "img_98.jpg\n",
      "Renamed 56023a17481b_11.jpg to img_98.jpg\n",
      "img_99.jpg\n",
      "Renamed 56023a17481b_12.jpg to img_99.jpg\n",
      "img_100.jpg\n",
      "Renamed 56023a17481b_13.jpg to img_100.jpg\n",
      "img_101.jpg\n",
      "Renamed 56023a17481b_14.jpg to img_101.jpg\n",
      "img_102.jpg\n",
      "Renamed 56023a17481b_15.jpg to img_102.jpg\n",
      "img_103.jpg\n",
      "Renamed 56023a17481b_16.jpg to img_103.jpg\n",
      "img_104.jpg\n",
      "Renamed 562706000bd7_01.jpg to img_104.jpg\n",
      "img_105.jpg\n",
      "Renamed 562706000bd7_02.jpg to img_105.jpg\n",
      "img_106.jpg\n",
      "Renamed 562706000bd7_03.jpg to img_106.jpg\n",
      "img_107.jpg\n",
      "Renamed 562706000bd7_04.jpg to img_107.jpg\n",
      "img_108.jpg\n",
      "Renamed 562706000bd7_05.jpg to img_108.jpg\n",
      "img_109.jpg\n",
      "Renamed 562706000bd7_06.jpg to img_109.jpg\n",
      "img_110.jpg\n",
      "Renamed 562706000bd7_07.jpg to img_110.jpg\n",
      "img_111.jpg\n",
      "Renamed 562706000bd7_08.jpg to img_111.jpg\n",
      "img_112.jpg\n",
      "Renamed 562706000bd7_09.jpg to img_112.jpg\n",
      "img_113.jpg\n",
      "Renamed 562706000bd7_10.jpg to img_113.jpg\n",
      "img_114.jpg\n",
      "Renamed 562706000bd7_11.jpg to img_114.jpg\n",
      "img_115.jpg\n",
      "Renamed 562706000bd7_12.jpg to img_115.jpg\n",
      "img_116.jpg\n",
      "Renamed 562706000bd7_13.jpg to img_116.jpg\n",
      "img_117.jpg\n",
      "Renamed 562706000bd7_14.jpg to img_117.jpg\n",
      "img_118.jpg\n",
      "Renamed 562706000bd7_15.jpg to img_118.jpg\n",
      "img_119.jpg\n",
      "Renamed 562706000bd7_16.jpg to img_119.jpg\n",
      "img_120.jpg\n",
      "Renamed 5a194c1384f3_01.jpg to img_120.jpg\n",
      "img_121.jpg\n",
      "Renamed 5a194c1384f3_02.jpg to img_121.jpg\n",
      "img_122.jpg\n",
      "Renamed 5a194c1384f3_03.jpg to img_122.jpg\n",
      "img_123.jpg\n",
      "Renamed 5a194c1384f3_04.jpg to img_123.jpg\n",
      "img_124.jpg\n",
      "Renamed 5a194c1384f3_05.jpg to img_124.jpg\n",
      "img_125.jpg\n",
      "Renamed 5a194c1384f3_06.jpg to img_125.jpg\n",
      "img_126.jpg\n",
      "Renamed 5a194c1384f3_07.jpg to img_126.jpg\n",
      "img_127.jpg\n",
      "Renamed 5a194c1384f3_08.jpg to img_127.jpg\n",
      "img_128.jpg\n",
      "Renamed 5a194c1384f3_09.jpg to img_128.jpg\n",
      "img_129.jpg\n",
      "Renamed 5a194c1384f3_10.jpg to img_129.jpg\n",
      "img_130.jpg\n",
      "Renamed 5a194c1384f3_11.jpg to img_130.jpg\n",
      "img_131.jpg\n",
      "Renamed 5a194c1384f3_12.jpg to img_131.jpg\n",
      "img_132.jpg\n",
      "Renamed 5a194c1384f3_13.jpg to img_132.jpg\n",
      "img_133.jpg\n",
      "Renamed 5a194c1384f3_14.jpg to img_133.jpg\n",
      "img_134.jpg\n",
      "Renamed 5a194c1384f3_15.jpg to img_134.jpg\n",
      "img_135.jpg\n",
      "Renamed 5a194c1384f3_16.jpg to img_135.jpg\n",
      "img_136.jpg\n",
      "Renamed 5ab34f0e3ea5_01.jpg to img_136.jpg\n",
      "img_137.jpg\n",
      "Renamed 5ab34f0e3ea5_02.jpg to img_137.jpg\n",
      "img_138.jpg\n",
      "Renamed 5ab34f0e3ea5_03.jpg to img_138.jpg\n",
      "img_139.jpg\n",
      "Renamed 5ab34f0e3ea5_04.jpg to img_139.jpg\n",
      "img_140.jpg\n",
      "Renamed 5ab34f0e3ea5_05.jpg to img_140.jpg\n",
      "img_141.jpg\n",
      "Renamed 5ab34f0e3ea5_06.jpg to img_141.jpg\n",
      "img_142.jpg\n",
      "Renamed 5ab34f0e3ea5_07.jpg to img_142.jpg\n",
      "img_143.jpg\n",
      "Renamed 5ab34f0e3ea5_08.jpg to img_143.jpg\n",
      "img_144.jpg\n",
      "Renamed 5ab34f0e3ea5_09.jpg to img_144.jpg\n",
      "img_145.jpg\n",
      "Renamed 5ab34f0e3ea5_10.jpg to img_145.jpg\n",
      "img_146.jpg\n",
      "Renamed 5ab34f0e3ea5_11.jpg to img_146.jpg\n",
      "img_147.jpg\n",
      "Renamed 5ab34f0e3ea5_12.jpg to img_147.jpg\n",
      "img_148.jpg\n",
      "Renamed 5ab34f0e3ea5_13.jpg to img_148.jpg\n",
      "img_149.jpg\n",
      "Renamed 5ab34f0e3ea5_14.jpg to img_149.jpg\n",
      "img_150.jpg\n",
      "Renamed 5ab34f0e3ea5_15.jpg to img_150.jpg\n",
      "img_151.jpg\n",
      "Renamed 5ab34f0e3ea5_16.jpg to img_151.jpg\n",
      "img_152.jpg\n",
      "Renamed 5bc30efeb7bf_01.jpg to img_152.jpg\n",
      "img_153.jpg\n",
      "Renamed 5bc30efeb7bf_02.jpg to img_153.jpg\n",
      "img_154.jpg\n",
      "Renamed 5bc30efeb7bf_03.jpg to img_154.jpg\n",
      "img_155.jpg\n",
      "Renamed 5bc30efeb7bf_04.jpg to img_155.jpg\n",
      "img_156.jpg\n",
      "Renamed 5bc30efeb7bf_05.jpg to img_156.jpg\n",
      "img_157.jpg\n",
      "Renamed 5bc30efeb7bf_06.jpg to img_157.jpg\n",
      "img_158.jpg\n",
      "Renamed 5bc30efeb7bf_07.jpg to img_158.jpg\n",
      "img_159.jpg\n",
      "Renamed 5bc30efeb7bf_08.jpg to img_159.jpg\n",
      "img_160.jpg\n",
      "Renamed 5bc30efeb7bf_09.jpg to img_160.jpg\n",
      "img_161.jpg\n",
      "Renamed 5bc30efeb7bf_10.jpg to img_161.jpg\n",
      "img_162.jpg\n",
      "Renamed 5bc30efeb7bf_11.jpg to img_162.jpg\n",
      "img_163.jpg\n",
      "Renamed 5bc30efeb7bf_12.jpg to img_163.jpg\n",
      "img_164.jpg\n",
      "Renamed 5bc30efeb7bf_13.jpg to img_164.jpg\n",
      "img_165.jpg\n",
      "Renamed 5bc30efeb7bf_14.jpg to img_165.jpg\n",
      "img_166.jpg\n",
      "Renamed 5bc30efeb7bf_15.jpg to img_166.jpg\n",
      "img_167.jpg\n",
      "Renamed 5bc30efeb7bf_16.jpg to img_167.jpg\n",
      "img_168.jpg\n",
      "Renamed 5bcde75955bb_01.jpg to img_168.jpg\n",
      "img_169.jpg\n",
      "Renamed 5bcde75955bb_02.jpg to img_169.jpg\n",
      "img_170.jpg\n",
      "Renamed 5bcde75955bb_03.jpg to img_170.jpg\n",
      "img_171.jpg\n",
      "Renamed 5bcde75955bb_04.jpg to img_171.jpg\n",
      "img_172.jpg\n",
      "Renamed 5bcde75955bb_05.jpg to img_172.jpg\n",
      "img_173.jpg\n",
      "Renamed 5bcde75955bb_06.jpg to img_173.jpg\n",
      "img_174.jpg\n",
      "Renamed 5bcde75955bb_07.jpg to img_174.jpg\n",
      "img_175.jpg\n",
      "Renamed 5bcde75955bb_08.jpg to img_175.jpg\n",
      "img_176.jpg\n",
      "Renamed 5bcde75955bb_09.jpg to img_176.jpg\n",
      "img_177.jpg\n",
      "Renamed 5bcde75955bb_10.jpg to img_177.jpg\n",
      "img_178.jpg\n",
      "Renamed 5bcde75955bb_11.jpg to img_178.jpg\n",
      "img_179.jpg\n",
      "Renamed 5bcde75955bb_12.jpg to img_179.jpg\n",
      "img_180.jpg\n",
      "Renamed 5bcde75955bb_13.jpg to img_180.jpg\n",
      "img_181.jpg\n",
      "Renamed 5bcde75955bb_14.jpg to img_181.jpg\n",
      "img_182.jpg\n",
      "Renamed 5bcde75955bb_15.jpg to img_182.jpg\n",
      "img_183.jpg\n",
      "Renamed 5bcde75955bb_16.jpg to img_183.jpg\n",
      "img_184.jpg\n",
      "Renamed 5d95d80e10a9_01.jpg to img_184.jpg\n",
      "img_185.jpg\n",
      "Renamed 5d95d80e10a9_02.jpg to img_185.jpg\n",
      "img_186.jpg\n",
      "Renamed 5d95d80e10a9_03.jpg to img_186.jpg\n",
      "img_187.jpg\n",
      "Renamed 5d95d80e10a9_04.jpg to img_187.jpg\n",
      "img_188.jpg\n",
      "Renamed 5d95d80e10a9_05.jpg to img_188.jpg\n",
      "img_189.jpg\n",
      "Renamed 5d95d80e10a9_06.jpg to img_189.jpg\n",
      "img_190.jpg\n",
      "Renamed 5d95d80e10a9_07.jpg to img_190.jpg\n",
      "img_191.jpg\n",
      "Renamed 5d95d80e10a9_08.jpg to img_191.jpg\n",
      "img_192.jpg\n",
      "Renamed 5d95d80e10a9_09.jpg to img_192.jpg\n",
      "img_193.jpg\n",
      "Renamed 5d95d80e10a9_10.jpg to img_193.jpg\n",
      "img_194.jpg\n",
      "Renamed 5d95d80e10a9_11.jpg to img_194.jpg\n",
      "img_195.jpg\n",
      "Renamed 5d95d80e10a9_12.jpg to img_195.jpg\n",
      "img_196.jpg\n",
      "Renamed 5d95d80e10a9_13.jpg to img_196.jpg\n",
      "img_197.jpg\n",
      "Renamed 5d95d80e10a9_14.jpg to img_197.jpg\n",
      "img_198.jpg\n",
      "Renamed 5d95d80e10a9_15.jpg to img_198.jpg\n",
      "img_199.jpg\n",
      "Renamed 5d95d80e10a9_16.jpg to img_199.jpg\n"
     ]
    }
   ],
   "source": [
    "# 第二步 重命名图像文件\n",
    "for i, image_file in enumerate(image_files):\n",
    "    ex_name = os.path.splitext(image_file)[1]\n",
    "    new_name = \"img_\" + str(i) + ex_name\n",
    "    print(new_name)\n",
    "    os.rename(os.path.join(path, image_file), os.path.join(path, new_name))\n",
    "    print(f\"Renamed {image_file} to {new_name}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "bb148b92-5b63-4cb3-83e3-151c83c9934a",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "AlexNet",
   "language": "python",
   "name": "alexnet"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
